package utils

import (
	"time"
)

type Trace struct {
	Sql       []string
	Http      []Http
	BeginTime time.Time
	EndTime   time.Time
	Execute   string
}

type Http struct {
	Runtime string      `json:"runtime"`
	Header  interface{} `json:"header"`
	Params  interface{} `json:"params"`
	Result  interface{} `json:"result"`
}

var TE = New()

func New() *Trace {
	trace := new(Trace)
	return trace
}

func (Debug *Trace) RequestBegin() {
	Debug.BeginTime = time.Now()
	Debug.Sql = []string{}
}

func (Debug *Trace) SetAnSql(logLevel string) {
	Debug.Sql = append(Debug.Sql, logLevel)
}

func (Debug *Trace) SetAnHttp(logLevel Http) {
	Debug.Http = append(Debug.Http, logLevel)
}

func (Debug *Trace) GetDebugData() *Trace {
	Debug.EndTime = time.Now()
	Debug.Execute = Debug.EndTime.Sub(Debug.BeginTime).String()
	return Debug
}
